package com.project.sianet.fragment;

import com.project.sianet.R;
import com.project.sianet.data.TabFragmentPagerAdapter;
import com.project.sianet.util.AlertDialogManager;
import com.viewpagerindicator.TabPageIndicator;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MensajesFragment extends Fragment {

	private int mTitleFrag;
	private String mSlideMsge = null;

	public MensajesFragment() {}
	
	public static final MensajesFragment newInstance() {
		MensajesFragment f = new MensajesFragment();
		Bundle args = new Bundle();
		args.putInt("mTitleFrag", R.string.title_bar_mensajes);
		f.setArguments(args);
		return f;
	}
	
	public static final MensajesFragment newInstance(String msje) {
		MensajesFragment f = new MensajesFragment();
		Bundle args = new Bundle();
		args.putInt("mTitleFrag", R.string.title_bar_mensajes);
		args.putString("mSlideMsge", msje);
		f.setArguments(args);
		return f;
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		return inflater.inflate(R.layout.fragment_mensajes, container, false);
		
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        mTitleFrag = getArguments().getInt("mTitleFrag");
        mSlideMsge = getArguments().getString("mSlideMsge");
        
        TextView title = (TextView)this.getActivity().findViewById(R.id.tv_title);
        LinearLayout shadow = (LinearLayout)this.getActivity().findViewById(R.id.layout_shadow);
		title.setText(mTitleFrag);
		shadow.setVisibility(LinearLayout.GONE);

		FragmentPagerAdapter adapter = new TabFragmentPagerAdapter(getChildFragmentManager(), getActivity());
		
        ViewPager pager = (ViewPager)this.getActivity().findViewById(R.id.pager);
        pager.setAdapter(adapter);
        
        TabPageIndicator indicator = (TabPageIndicator)this.getActivity().findViewById(R.id.indicator);        
        indicator.setViewPager(pager);
        
        if (mSlideMsge != null) {
        	AlertDialogManager.showSlideMessage(this.getActivity(), mSlideMsge);
        	mSlideMsge = null;
        	getArguments().remove("mSlideMsge");
        }
        
    }
	
}
